/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ttfsclient;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import pojo.POJODownloadClient;
import myutil.XMLHelper;

/**
 *
 * @author Tidus Le
 */
public class clsXMLDownloadClient
{
    /**
     * Đọc thông tin của client từ file xml
     */
    public static void read(ArrayList<POJODownloadClient> arrDownloadClient)
    {
        ArrayList<Hashtable<String,String>> arrElements=XMLHelper.read("DownloadClient");
        
        for(Hashtable<String,String> element:arrElements)
        {
            POJODownloadClient fu=new POJODownloadClient();
            Enumeration e=element.keys();
              while(e.hasMoreElements())
              {
                  String key=(String)e.nextElement();
                  if(key.equals("fid")==true)
                      fu.setFid(element.get(key));
                  else
                      if(key.equals("cid")==true)
                        fu.setCid(element.get(key));
                      else
                          if(key.equals("cname")==true)
                            fu.setCname(element.get(key));
              }
            arrDownloadClient.add(fu);
        }
    }
    
    /**
     * Ghi thông tin vào file xml
     */
    public static void write(ArrayList<POJODownloadClient> arrDownloadClient)
    {
        ArrayList<Hashtable<String,String>> arrElements=new ArrayList<Hashtable<String, String>>();
        
        for(POJODownloadClient fu:arrDownloadClient)
        {
            Hashtable<String,String> element=new Hashtable<String, String>();
            element.put("fid", fu.getFid());
            element.put("cid", fu.getCid());
            element.put("cname", fu.getCname());
            arrElements.add(element);
        }
        
        XMLHelper.write("DownloadClient", arrElements);
    }
}
